
import { Controller, Get, Post, Put, Body, Query, Param, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { TeacherService } from './teacher.service';
import { CreateTeacherDto, BaseTeacherDto, UpdateTeacherDto, QueryTeacherDto, ListTeacherDto } from './dto/teacher.dto';
import { ApiDataResponse } from 'src/common/decorators/apiDataResponse.decorator';
import { UserTool, UserToolType } from 'src/module/system/user/user.decorator';
import { RepeatSubmit } from 'src/common/decorators/repeat-submit.decorator';
import { Operlog } from 'src/common/decorators/operlog.decorator';
import { BusinessType } from 'src/common/constant/business.constant';

@ApiTags('教师')
@Controller('edutation/teacher')
export class TeacherController {
    constructor(private readonly teacherService: TeacherService) {}
    @ApiOperation({ summary: '教师-创建',  })
    @ApiDataResponse(BaseTeacherDto)
    @RequirePermission('edutation:teacher:add')
    @Post()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.INSERT })
    create(@Body() body: CreateTeacherDto,@UserTool() { injectCreate }: UserToolType) {
        return this.teacherService.create(injectCreate(body));
    }


    @ApiOperation({ summary: '教师-列表',  })
    @ApiDataResponse(ListTeacherDto, true, true)
    @RequirePermission('edutation:teacher:list')
    @Get('list')
    findAll(@Query() query: QueryTeacherDto) {
        return this.teacherService.findAll(query);
    }


    @ApiOperation({  summary: '教师-详情',    })
    @ApiDataResponse(BaseTeacherDto)
    @RequirePermission('edutation:teacher:query')
    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.teacherService.findOne(+id);
    }


    @ApiOperation({ summary: '教师-修改',  })
    @ApiDataResponse()
    @RequirePermission('edutation:teacher:edit')
    @Put()
    @RepeatSubmit()
    @Operlog({ businessType: BusinessType.UPDATE })
    update(@Body() body: UpdateTeacherDto,@UserTool() { injectUpdate }: UserToolType) {
        return this.teacherService.update(injectUpdate(body));
    }


    @ApiOperation({  summary: '教师-删除', })
    @ApiDataResponse()
    @RequirePermission('edutation:teacher:remove')
    @Delete(':ids')
    @Operlog({ businessType: BusinessType.DELETE })
    remove(@Param('ids') ids: string) {
        const idList = ids.split(',').map((id) => +id);
        return this.teacherService.remove(idList);
    }
}
